package com.zy.pay.demo.sample;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.zy.pay.api.request.ZyPayOrderColseRequest;
import com.zy.pay.api.request.ZyPayOrderQueryRequest;
import com.zy.pay.api.request.ZyPayOrderRefundQueryRequest;
import org.junit.Test;

import com.zy.pay.api.ZyPayClient;
import com.zy.pay.api.ZyPayDefaultClient;
import com.zy.pay.api.request.ZyPayOrderRefundRequest;

/**
 * 支付测试 <br>
 *
 * @author panweiqiang <br>
 * @date 2020/7/7 20:02 <br>
 */
public class ZyPayDemo {

    private static final String URL      = "https://unifiedpay.lsmart.wang";

    private static final String CP_CODE  = "yiyun";

    private static final String SIGN_KEY = "123456";

    private static final String APPID    = "1805161648277001";

    @Test
    public void testOrderRefund() {
        ZyPayOrderRefundRequest request = new ZyPayOrderRefundRequest();
        request.setCpTranNo("12");
        request.setCpRefundTranNo("12");
        request.setRefundReason("测试退款");
        request.setTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
        getClient().execute(request);
    }

    @Test
    public void testOrderQuery() {
        ZyPayOrderQueryRequest request = new ZyPayOrderQueryRequest();
        request.setCpTranNo("1");
        request.setTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
        getClient().execute(request);
    }

    @Test
    public void testOrderRefundQuery() {
        ZyPayOrderRefundQueryRequest request = new ZyPayOrderRefundQueryRequest();
        request.setCpRefundTranNo("1");
        request.setTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
        getClient().execute(request);
    }

    @Test
    public void testOrderClose() {
        ZyPayOrderColseRequest request = new ZyPayOrderColseRequest();
        request.setCpTranNo("1");
        request.setTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
        getClient().execute(request);
    }

    private ZyPayClient getClient() {
        return new ZyPayDefaultClient(URL, CP_CODE, SIGN_KEY, APPID);
    }
}
